<!DOCTYPE HTML>
<html>
<head>
<title>IfInString / IfNotInString | AutoHotkey</title>
<meta name="description" content="The IfInString and IfNotInString statements check whether a variable contains the specified string or not." />
<meta name="ahk:equiv-v2" content="commands/InStr.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>IfInString / IfNotInString</h1>

<p>检查<a href="../Variables.htm">变量</a>是否包含指定的字符串.</p>
<p class="warning"><strong>过时的:</strong> 不推荐在新脚本中使用这些命令. 请使用 <a href="InStr.htm">InStr</a> 函数代替.</p>

<pre class="Syntax">
<span class="func">IfInString</span>, Var, SearchString
<span class="func">IfNotInString</span>, Var, SearchString
</pre>

<h2 id="Parameters">参数</h2>
<dl>

  <dt>Var</dt>
  <dd><p>为寻找匹配而被搜索的<a href="../Variables.htm">变量</a>名称.</p></dd>

  <dt>SearchString</dt>
  <dd><p>要搜索的字符串. 如果没有启用 <a href="StringCaseSense.htm">StringCaseSense</a>, 那么匹配过程不区分大小写.</p></dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>内置变量 <a href="../Variables.htm">%A_Space%</a> 和 <a href="../Variables.htm">%A_Tab%</a> 分别包含单个空格和单个 tab 字符, 单独搜索这些字符时它们可能很有用.</p>
<p>另一个命令可以和此命令在同一行. 换句话说, 这两个语句是等同的:</p>
<pre>IfInString, MyVar, abc, Gosub, Process1
IfInString, MyVar, abc
    Gosub, Process1</pre>
<p>不过, 除命名命令外的其他项不支持与此命令在相同行. 例如:</p>
<pre>IfInString, MyVar, abc, found := true  <em><strong>; 无效的.</strong></em></pre>
<h2 id="Related">相关</h2>
<p><a href="InStr.htm">InStr()</a>, <a href="RegExMatch.htm">RegExMatch()</a>, <a href="StringGetPos.htm">StringGetPos</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="IfEqual.htm">IfEqual</a>, <a href="IfIn.htm">if var in/contains MatchList</a>, <a href="IfBetween.htm">if var between</a>, <a href="IfIs.htm">if var is type</a>, <a href="Block.htm">Blocks</a>, <a href="Else.htm">Else</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a class="ex_number" href="#ExBasic"></a> 检查 <var>Haystack</var> 是否包含子字符串 "abc".</p>
<pre>Haystack = abcdefghijklmnopqrs
Needle := "abc"
IfInString, Haystack, %Needle%
{
    MsgBox, The string was found.
    return
}
else
    Sleep, 1</pre>
</div>

</body>
</html>